<?php

declare(strict_types=1);
/**
 * Fastapp.
 * 3/7/24
 * @Author deepsea
 * @Contact telegram:deepsea159
 */

namespace App\Fastapp\Api\Controller\Account;


use App\Fastapp\Api\Controller\ApiController;
use App\Fastapp\Api\Service\Account\ShareService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Http\Message\ResponseInterface;

#[Controller(prefix: "api/share")]
class ShareController extends ApiController
{
    #[Inject]
    public ShareService $service;

    #[PostMapping('create')]
    public function create(): ResponseInterface
    {
        return $this->success($this->service->create($this->validate(self::RULE, [
            'type.*' => fastapp_t('account.v_19'),
            'content.*' => fastapp_t('account.v_20'),
        ])));
    }

    #[GetMapping('detail')]
    public function detail(): ResponseInterface
    {
        return $this->success($this->service->detail((int)$this->request->input('share_id')));
    }

    #[GetMapping('poster')]
    public function poster(): ResponseInterface
    {
        return $this->response->raw($this->service->poster($this->request->all()))->withHeader('Content-type', 'image/png');
    }

    #[GetMapping('wxmini')]
    public function wxmini(): ResponseInterface
    {
        return $this->response->raw($this->service->wxmini($this->request->all()))->withHeader('Content-type', 'image/png');
    }

    #[GetMapping('invite')]
    public function invite(): ResponseInterface
    {
        return $this->success($this->service->invite());
    }

    #[GetMapping('dashboard')]
    public function dashboard(): ResponseInterface
    {
        return $this->success($this->service->dashboard());
    }

    #[GetMapping('income')]
    public function income(): ResponseInterface
    {
        return $this->success($this->service->income());
    }

    const RULE = [
        'type' => 'required|integer',
        'object_id' => 'integer',
        'date' => 'date',
        'content' => 'required|array',
    ];
}